//Documentation complete
/**
 * @author Kazu
 * @version 2009MR27
 */

package ui.internal;

import static utilities.XMLTools.encapsulateBeanListXML;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import problemDomain.ErrorBean;
import problemDomain.MenuItemReport;

import control.CostProfitByMenuItemReportControl;

/**
 * Servlet implementation class ReportCostProfitByMenuItem
 */
public class ReportCostProfitByMenuItem extends HttpServlet {
    
	/* Constants */
	
	private static final long serialVersionUID = -6817546367748924474L;
	
	/* END Constants */
	
	
	/* (HttpServlet) Methods */
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		response.setContentType("text/xml");
		if (session != null) {
			String action = request.getParameter("a");
			if (action != null) {
				if (action.equalsIgnoreCase("3"))
					getCostProfitByMIReport(request, response);
			}
		}
	}
	
	/* END (HttpServlet) Methods */
	
	
	/* Local Methods */
	
	private void getCostProfitByMIReport(HttpServletRequest request, HttpServletResponse response) throws IOException {
		/*String fromDay = request.getParameter("fromday");
		String fromMonth = request.getParameter("frommonth");
		String fromYear = request.getParameter("fromyear");
		String toDay = request.getParameter("today");
		String toMonth = request.getParameter("tomonth");
		String toYear = request.getParameter("toyear");*/
		
		String fromDate = request.getParameter("fromdate");
		String toDate = request.getParameter("todate");
		
		PrintWriter out = response.getWriter();
		try {
			CostProfitByMenuItemReportControl rptCtrl = new CostProfitByMenuItemReportControl();
			List<MenuItemReport> list = rptCtrl.getCostProfitByMIReport(fromDate, toDate);
							//fromDay, fromMonth, fromYear, toDay, toMonth, toYear);
			out.write(encapsulateBeanListXML(list, "menuitem-reports"));
		} catch (ErrorBean e) {
			out.write(e.toXML());
		} finally {
			out.close();
		}
	}
	
	/* END Local Methods */
	
}
